package com.chuanke.ckfamily.job;

import com.chuanke.ckfamily.service.common.SynizedExcuter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.chuanke.ckfamily.dao.base.CkUtil;
import com.chuanke.ckfamily.service.common.CacheService;
import com.chuanke.ckfamily.service.finance.FamilyDayIncomeService;
import com.chuanke.ckfamily.service.social.FamilyService;

public class IncomeTask {

	private static final Logger log = LoggerFactory.getLogger(IncomeTask.class);

	@Autowired
	private FamilyDayIncomeService dayIncomeService;

	@Autowired
	private FamilyService familyService;

	@Autowired
	private CacheService cacheService;

	/**
	 * 每日结算
	 */
	public void dayIncome() {
		new SynizedExcuter() {
			@Override
			public void excute() {
				log.debug("开始执行分账业务=====================>");
				IncomeTask.this.excuteDayIncomeTask();
			}
		}.run(cacheService, CacheService.KEY_PREFIX.dayIncome_.name(), 1200000);
	}

	private void excuteDayIncomeTask() {
		try {
			String tdate = CkUtil.getYesterdayStr();
			dayIncomeService.countIncome(tdate);
			familyService.refreshRank(tdate);

		} catch (Exception e) {
			e.printStackTrace();

		}
	}

}
